package com.infocollect.project.grant.controller;

import java.util.List;

import com.infocollect.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.infocollect.framework.aspectj.lang.annotation.Log;
import com.infocollect.framework.aspectj.lang.enums.BusinessType;
import com.infocollect.project.grant.domain.GrGrant;
import com.infocollect.project.grant.service.IGrGrantService;
import com.infocollect.framework.web.controller.BaseController;
import com.infocollect.framework.web.domain.AjaxResult;
import com.infocollect.common.utils.poi.ExcelUtil;
import com.infocollect.framework.web.page.TableDataInfo;

/**
 * 报名项目Controller
 * 
 * @author infocollect
 * @date 2022-05-14
 */
@RestController
@RequestMapping("/grant/grant")
public class GrGrantController extends BaseController
{
    @Autowired
    private IGrGrantService grGrantService;

    /**
     * 查询报名项目列表
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrGrant grGrant)
    {
        startPage();
        List<GrGrant> list = grGrantService.selectGrGrantList(grGrant);
        return getDataTable(list);
    }

    /**
     * 导出报名项目列表
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:export')")
    @Log(title = "报名项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GrGrant grGrant)
    {
        List<GrGrant> list = grGrantService.selectGrGrantList(grGrant);
        ExcelUtil<GrGrant> util = new ExcelUtil<GrGrant>(GrGrant.class);
        return util.exportExcel(list, "grant");
    }

    /**
     * 获取报名项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:query')")
    @GetMapping(value = "/{grantId}")
    public AjaxResult getInfo(@PathVariable("grantId") Long grantId)
    {
        return AjaxResult.success(grGrantService.selectGrGrantById(grantId));
    }

    /**
     * 新增报名项目
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:add')")
    @Log(title = "报名项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrGrant grGrant)
    {
        grGrant.setCreateUser(SecurityUtils.getLoginUser().getUserId());
        return toAjax(grGrantService.insertGrGrant(grGrant));
    }

    /**
     * 修改报名项目
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:edit')")
    @Log(title = "报名项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrGrant grGrant)
    {
        return toAjax(grGrantService.updateGrGrant(grGrant));
    }

    /**
     * 删除报名项目
     */
    @PreAuthorize("@ss.hasPermi('grant:grant:remove')")
    @Log(title = "报名项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{grantIds}")
    public AjaxResult remove(@PathVariable Long[] grantIds)
    {
        return toAjax(grGrantService.deleteGrGrantByIds(grantIds));
    }
    /**
     * 查询报名项目列表不分页全理查询
     */
    @GetMapping("/listAll")
    public AjaxResult listAll(GrGrant grGrant)
    {
        List<GrGrant> list = grGrantService.selectGrGrantList(grGrant);
        return AjaxResult.success(list);
    }
}
